<template>
  <span>
    <el-input v-model="documentNO" disabled class="el-form--widthBig" />
  </span>
</template>

<script>
import { getReceiptNum } from '@/api/common/common'
import { mapGetters } from 'vuex'
export default {
  name: 'ReceiptNo',
  props: {
    // 单据日期
    date: {
      type: String,
      required: true
    },
    // 单据类型
    typeId: {
      type: [String, Number],
      required: true
    },
    // 是否是编辑
    editState: {
      type: Boolean
      // required: true
    },
    // 服务器单据号
    receiptNum: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      documentNO: '',
      timer: null
    }
  },
  computed: {
    ...mapGetters(['token'])
  },
  watch: {
    receiptNum: {
      handler(val) {
        if (this.editState) {
          this.documentNO = val
        }
      },
      immediate: true
    },
    date: {
      handler(val) {
        // console.log(val)
        if (!val || val === 'Invalid Date') {
          this.documentNO = ''
          return false
        }
        if (!this.editState) {
          this.getReceiptNoComp(val)
        }
      },
      immediate: true
    }
  },
  created() {
  },
  methods: {
    getReceiptNoComp(date) {
      getReceiptNum(
        {
          lngoperatorid: this.token.LNGOPERATORID,
          lngorganizeid: this.token.LNGORGANIZEID,
          lngproductid: 315,
          lngreceipttypeid: this.typeId,
          receiptdate: date
        }
      ).then(res => {
        if (res.code === 20000) {
          this.documentNO = res.data.receiptno
          this.$emit('get-data', res.data)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
